package controllers

import (
	"ABlog/util"
	"github.com/astaxie/beego"
	"io/ioutil"
)

type EditArticleController struct {
	beego.Controller
}

func (c *EditArticleController) Get() {
	id := c.GetString("id", "")
	articlePath := util.GetArticlePath(id)

	exist, _ := util.PathExists(articlePath)
	if exist {
		data, err := ioutil.ReadFile(articlePath)
		if err != nil {
			c.Data["Content"] = ""
		} else {
			c.Data["Content"] = string(data)
		}
	} else {
		c.Data["Content"] = ""
	}

	c.Data["ID"] = id
	// render
	c.TplName = "add_article.tpl"
}
